package com.example.springbootproject.controller;/*
 *@author 王志威
 *@datatime 2024/4/21 19:59
 *@editnote
 */

import com.example.springbootproject.pojo.Teacher;
import com.example.springbootproject.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Slf4j
@RequestMapping("/user")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    //显示教师信息页面
    @RequestMapping("/teacherInfo")
    public String teacher(){
        log.info("teacher");
        return "redirect:TeacherInformation";
    }
    //添加教师信息
    @PostMapping("/addTeacher")
    public String addTeacher(@RequestBody Teacher teacher){
        //向数据库中添加教师信息
        teacherService.addTeacher(teacher);
        return "redirect:/user/teacherInfo";
    }
    //删除教师信息
    @RequestMapping("/deleteTeacher")
    public String deleteTeacher(Integer id){
        //向数据库中删除教师信息
        teacherService.deleteTeacher(id);
        return "redirect:/user/teacherInfo";
    }
    //修改教师信息
    @RequestMapping("/updateTeacher")
    public String updateTeacher(Teacher teacher){
        //向数据库中修改教师信息
        teacherService.updateTeacher(teacher);
        return "redirect:/user/teacherInfo";
    }
    //查询教师信息
    @RequestMapping("/findTeacher")
    public String findTeacher(Integer id){
        //向数据库中查询教师信息
        teacherService.findTeacher(id);
        return "redirect:/user/teacherInfo";
    }
}
